package com.example.reactordemo.mapper;

import com.example.reactordemo.domain.Student;
import org.springframework.data.r2dbc.repository.Modifying;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.repository.reactive.ReactiveSortingRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Mono;

@Repository
public interface SpringWebFluxMapper extends ReactiveSortingRepository<Student,Long> {

    /**
     * 对象形式传参：:#{#对象名.字段名}
     * 字段传参：:字段名(@param定义)
     * 复杂查询同理
     */
    @Modifying
    @Query("insert into student(code,name,gender,active,address) values(:#{#student.code},:#{#student.name},:#{#student.gender},:#{#student.active},:#{#student.address})")
    Mono<Integer> insertDefined(Student student);

    @Modifying
    @Query("update student set name = :name where id = :id")
    Mono<Integer> updateDefined(@Param("id") Long id, @Param("name")String name);
}

